const HtmlWebpackPlugin = require("html-webpack-plugin")

module.exports = {
    mode: "none",
    entry: "./src/main.js",
    output: {
        filename: "bundle.js",
        path: path.join(__dirname, "dist"),
        // publicPath: "dist/"
    },
    devtool: "source-map", 
    devServer: {
        hot: true,
        contentBase: "./public",
        proxy: {
            "/api": {
                // http://localhost:8080/api/users => https://api.github.com/api/users
                target: "https://api.github.com",
                // http://localhost:8080/api/users => https://api.github.com/users
                pathRewrite: {
                    '^/api': ''
                },
                // 不能使用 localhost:8080 作为请求 Github 的主机名
                changeOrigin: true
            }
        }
    },
    module: {
        rules: [{
            test: /.md$/,
            use: [
                "html-loader",
                "./markdown-loader"
            ]
        }]
    },
    plugins: [
        // new CleanWebpackPlugin(),
        // 用于生成index.html
        new HtmlWebpackPlugin({
            title: "Webpack Plugin Sample",
            meta: {
                viewport: "width=device-width"
            },
            template: "./src/index.html"
        }),
        // 用于生成 about.html
        new HtmlWebpackPlugin({
            filename: "about.html"
        }),
        // new CopyWebpackPlugin({
        //     patterns: [
        //         {
        //             from: "public"
        //         }
        //     ]
        // }),
        new MyPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ]
}